<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="utf-8">
		<title>批量导入家长</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../css/parentManagement.css"/>
		<style type="text/css">
		.importParents .model{
			margin-top: 40px;
		}
		.importParents .model label {
			font-size: 15px;
		}
		</style>
	</head>
<body>
	<div class="importParents">
		<div class="layui-block importParents-con">
			<div class="layui-form-item">
				<button type="button" class="layui-btn leftbtn" id="test4">
					<i class="layui-icon"></i>选择Excel文件
				</button>
				<button type="reset" class="layui-btn layui-btn-primary rightbtn">下载模板</button>
				<button type="button" class="layui-btn savebtn" lay-submit="" lay-filter="demo1" id="saveParList">保存</button>
			</div>
		</div>
		<table class="layui-hide" id="teacher"></table>
		<div class="model">
			<script type="text/html" id="toolbarDemo">
				<label>导入失败的数据</label>
			</script>
			<table class="layui-hide" id="parentData"></table>
		</div>
	</div>
	<script src="../layui/layui.all.js" charset="utf-8"></script>
	<script src="../js/jquery-3.3.1.js"></script>
	<script>
		layui.use([ 'table', 'upload' ], function() {
			var $ = layui.jquery, upload = layui.upload, table = layui.table;

			//指定允许上传的文件类型
			upload.render({ //允许上传的文件后缀
				elem : '#test4',
				url : '../sysparentmanagement/getexceltablelist',
				accept : 'file', //普通文件
				exts : 'xls|xlsx|xlsm', //只允许上传压缩文件
				acceptMime : 'xls|xlsx|xlsm',
				done : function(res) {
					if (res.code == 0) {
						table.render({
							elem : '#teacher',
							method : 'post',
							url: '../sysparentmanagement/excelloadtable?op=0',
							title : '家长数据表',
							skin : 'line',
							even : true,
							cols : [ [{
								field : 'realName',
								align: "center",
								title : '真实姓名'
							}, {
								field : 'sex',
								align: "center",
								title : '性别'
							}, {
								field : 'phone',
								align: "center",
								title : '联系电话'
							}, {
								field : 'birthday',
								align: "center",
								title : '生日'
							} ] ]
						});
					} else {
						alert('打开失败！')
					}
				}
			});

			$("#saveParList").click(function() {
				$.ajax({
					type : 'get',
					url : '../sysparentmanagement/saveparlist',
					datatype : 'json',
					success : function(data) {
						if (data.code == 0) {
							layer.msg(data.msg)
						} else {
							layer.msg(data.msg)
							table.render({
							elem : '#toolbarDemo',
							toolbar: '#toolbarDemo',
							method : 'post',
							url: '../sysparentmanagement/excelloadtable?op=1',
							title : '家长数据表',
							skin : 'line',
							even : true,
							cols : [ [{
								field : 'realName',
								title : '真实姓名'
							}, {
								field : 'sex',
								title : '性别'
							}, {
								field : 'phone',
								title : '联系电话'
							}, {
								field : 'birthday',
								title : '生日'
							} ] ]
						});
						}
					},
					error : function() {
					}
				});

			});
		});
	</script>
</body>
</html>